<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java 内存泄漏分析完全指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            padding: 20px;
            overflow-x: auto;
            font-family: 'Consolas', 'Monaco', monospace;
        }
        
        .symptom-card {
            background: white;
            border-left: 4px solid;
            border-image: linear-gradient(135deg, #667eea 0%, #764ba2 100%) 1;
        }
        
        .tool-card {
            background: linear-gradient(135deg, #f5f7fa 0%, #ffffff 100%);
            border: 1px solid rgba(102, 126, 234, 0.1);
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 40px 0;
        }
        
        .first-letter {
            float: left;
            font-size: 4rem;
            line-height: 3rem;
            padding-right: 8px;
            margin-top: 4px;
            font-weight: 700;
            color: #667eea;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6">
                    Java 内存泄漏分析
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">
                    深入理解、精准定位、彻底解决
                </p>
                <div class="flex justify-center space-x-4">
                    <span class="inline-flex items-center px-4 py-2 bg-white bg-opacity-20 rounded-full">
                        <i class="fas fa-memory mr-2"></i>
                        内存优化
                    </span>
                    <span class="inline-flex items-center px-4 py-2 bg-white bg-opacity-20 rounded-full">
                        <i class="fas fa-chart-line mr-2"></i>
                        性能提升
                    </span>
                    <span class="inline-flex items-center px-4 py-2 bg-white bg-opacity-20 rounded-full">
                        <i class="fas fa-tools mr-2"></i>
                        工具实践
                    </span>
                </div>
            </div>
        </div>
    </section>

    <!-- Introduction -->
    <section class="py-16 bg-white">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto">
                <p class="text-lg leading-relaxed text-gray-700">
                    <span class="first-letter">在</span>Java 中进行内存泄漏分析是一个重要的任务，因为内存泄漏会导致应用程序占用过多内存，最终可能导致程序崩溃或性能问题。内存泄漏分析包括识别症状、使用 JVM 工具监控、使用 GC 日志和性能分析工具，以及代码审查和优化。通过这些方法，可以有效地检测和修复 Java 应用程序中的内存泄漏问题。
                </p>
            </div>
        </div>
    </section>

    <!-- Memory Leak Analysis Process -->
    <section class="py-16">
        <div class="container mx-auto px-6">
            <div class="max-w-6xl mx-auto">
                <h2 class="text-3xl font-bold text-center mb-12 text-gradient">内存泄漏分析流程图</h2>
                <div class="mermaid">
                    graph TD
                        A[发现内存问题] --> B{识别症状}
                        B --> C[高内存使用]
                        B --> D[频繁GC]
                        B --> E[性能下降]
                        C --> F[JVM工具监控]
                        D --> F
                        E --> F
                        F --> G[生成堆转储]
                        G --> H[分析工具]
                        H --> I[Eclipse MAT]
                        H --> J[VisualVM]
                        H --> K[YourKit]
                        I --> L[定位泄漏源]
                        J --> L
                        K --> L
                        L --> M[代码审查]
                        M --> N[修复问题]
                        N --> O[性能调优]
                </div>
            </div>
        </div>
    </section>

    <!-- Symptoms Section -->
    <section class="py-16 bg-gray-50">
        <div class="container mx-auto px-6">
            <div class="max-w-6xl mx-auto">
                <h2 class="text-3xl font-bold mb-12 section-title">1. 识别内存泄漏的症状</h2>
                <p class="text-lg text-gray-700 mb-8">在开始分析之前，需要识别内存泄漏的迹象：</p>
                
                <div class="grid md:grid-cols-3 gap-6">
                    <div class="symptom-card p-6 rounded-lg shadow-md card-hover">
                        <div class="flex items-center mb-4">
                            <i class="fas fa-chart-area text-3xl text-purple-600 mr-4"></i>
                            <h3 class="text-xl font-bold">高内存使用</h3>
                        </div>
                        <p class="text-gray-600">应用程序的内存使用量不断增加，超出了预期。</p>
                    </div>
                    
                    <div class="symptom-card p-6 rounded-lg shadow-md card-hover">
                        <div class="flex items-center mb-4">
                            <i class="fas fa-recycle text-3xl text-purple-600 mr-4"></i>
                            <h3 class="text-xl font-bold">频繁的垃圾回收</h3>
                        </div>
                        <p class="text-gray-600">垃圾回收器频繁运行，但内存使用率没有显著下降。</p>
                    </div>
                    
                    <div class="symptom-card p-6 rounded-lg shadow-md card-hover">
                        <div class="flex items-center mb-4">
                            <i class="fas fa-tachometer-alt text-3xl text-purple-600 mr-4"></i>
                            <h3 class="text-xl font-bold">性能下降</h3>
                        </div>
                        <p class="text-gray-600">应用程序的响应时间变长，可能导致慢响应或无响应。</p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- JVM Tools Section -->
    <section class="py-16 bg-white">
        <div class="container mx-auto px-6">
            <div class="max-w-6xl mx-auto">
                <h2 class="text-3xl font-bold mb-12 section-title">2. 使用 JVM 工具进行初步分析</h2>
                
                <div class="grid md:grid-cols-2 gap-8">
                    <div class="tool-card p-8 rounded-lg card-hover">
                        <div class="flex items-center mb-6">
                            <i class="fas fa-desktop text-4xl text-purple-600 mr-4"></i>
                            <h3 class="text-2xl font-bold">JVisualVM</h3>
                        </div>
                        <p class="text-gray-700 mb-4">Java 8 附带的工具，用于监控 JVM 的运行情况，包括内存使用、线程活动和垃圾回收。</p>
                        <ul class="space-y-3">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-600 mr-3 mt-1"></i>
                                <div>
                                    <strong>监视内存使用</strong>：检查堆内存的使用情况和对象的分配情况。
                                </div>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-600 mr-3 mt-1"></i>
                                <div>
                                    <strong>创建堆转储（Heap Dump）</strong>：可以生成堆转储文件，后续分析对象的内存占用情况。
                                </div>
                            </li>
                        </ul>
                    </div>
                    
                    <div class="tool-card p-8 rounded-lg card-hover">
                        <div class="flex items-center mb-6">
                            <i class="fas fa-terminal text-4xl text-purple-600 mr-4"></i>
                            <h3 class="text-2xl font-bold">JConsole</h3>
                        </div>
                        <p class="text-gray-700 mb-4">Java 6 及以上版本提供的监控工具，用于查看 JVM 的内存、线程和其他运行时统计数据。</p>
                        <ul class="space-y-3">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-600 mr-3 mt-1"></i>
                                <div>
                                    <strong>监视内存使用</strong>：检查堆和非堆内存的使用情况。
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Heap Dump Analysis -->
    <section class="py-16 bg-gray-50">
        <div class="container mx-auto px-6">
            <div class="max-w-6xl mx-auto">
                <h2 class="text-3xl font-bold mb-12 section-title">3. 使用堆转储（Heap Dump）分析工具</h2>
                
                <div class="mb-12">
                    <h3 class="text-2xl font-bold mb-6 flex items-center">
                        <i class="fas fa-database text-purple-600 mr-3"></i>
                        生成堆转储
                    </h3>
                    <div class="bg-white p-6 rounded-lg shadow-md">
                        <p class="text-gray-700 mb-4">使用 JVM 参数 <code class="bg-gray-100 px-2 py-1 rounded">-XX:+HeapDumpOnOutOfMemoryError</code> 自动生成堆转储。</p>
                        <p class="text-gray-700 mb-4">使用 <code class="bg-gray-100 px-2 py-1 rounded">jmap</code> 工具手动生成堆转储：</p>
                        <div class="code-block">
                            jmap -dump:live,format=b,file=heapdump.hprof &lt;PID&gt;
                        </div>
                    </div>
                </div>
                
                <div>
                    <h3 class="text-2xl font-bold mb-6 flex items-center">
                        <i class="fas fa-search text-purple-600 mr-3"></i>
                        分析堆转储
                    </h3>
                    <div class="grid md:grid-cols-3 gap-6">
                        <div class="bg-white p-6 rounded-lg shadow-md card-hover">
                            <h4 class="text-xl font-bold mb-3 text-purple-600">Eclipse MAT</h4>
                            <p class="text-gray-700 mb-4">强大的工具，用于分析堆转储，识别内存泄漏。</p>
                            <ul class="space-y-2 text-sm">
                                <li><i class="fas fa-angle-right text-purple-600 mr-2"></i>导入堆转储</li>
                                <li><i class="fas fa-angle-right text-purple-600 mr-2"></i>分析泄漏</li>
                                <li><i class="fas fa-angle-right text-purple-600 mr-2"></i>对象查找</li>
                            </ul>
                        </div>